package com.example.visitedsys.utils;

import com.example.visitedsys.informationGet.NoticeV0;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName chong
 * @Description TODO
 * @Author xiguan
 * @Date 2021/12/13 9:31
 * @Version 1.0.0
 **/
@Component
public class chong {

    public List<Object> chong(){

        String url = "http://www.sicnu.edu.cn/";
        List<Object> NoticeList=new ArrayList<Object>();

//        Map<String,Object> map=new HashMap<>();
        try{
            Document document = Jsoup.connect(url).get();
            Elements elements = document.select("ul.new-ul");
            for(int i = 0; i < 10; ++ i)
            {
                String title = elements.select("a").get(i).text();
                String target_url = elements.select("a").get(i).attr("href");
                String time = elements.select("span").get(i).text();
                NoticeV0 noticeV0 = new NoticeV0(title,target_url,time);
//                System.out.println(noticeV0);
                NoticeList.add(noticeV0);
            }
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return NoticeList;
    }
}

